/**
 * 特勤处相关API
 */
import { apiClient } from './index'
import type { ApiResponse } from './types/common'
import type {
  SpecialOperationItem,
  SpecialOperationQueryParams,
  SpecialOperationListResponse,
  MaterialInfo,
  BulkMaterialInfoResponse
} from '@/types/specialOperation'

// 特勤处API端点
export const SPECIAL_OPERATION_API = {
  GET_LIST: '/SpecialOperation/getList',
  GET_DETAIL: '/SpecialOperation/getDetail',
  GET_MATERIAL_INFO: '/SpecialOperation/getMaterialInfo',
  GET_BULK_MATERIAL_INFO: '/SpecialOperation/getBulkMaterialInfo', // 注意：这里没有下划线
  GET_ALL_MATERIALS: '/SpecialOperation/all_materials'
}

/**
 * 获取特勤处操作列表
 * @param params 查询参数
 * @returns Promise
 */
export async function getSpecialOperationList(
  params?: SpecialOperationQueryParams
): Promise<ApiResponse<SpecialOperationListResponse>> {
  return apiClient.get<SpecialOperationListResponse>(
    SPECIAL_OPERATION_API.GET_LIST,
    {
      params
    }
  )
}

/**
 * 获取特勤处操作详情
 * @param id 操作ID
 * @returns Promise
 */
export async function getSpecialOperationDetail(
  id: number
): Promise<ApiResponse<SpecialOperationItem>> {
  return apiClient.get<SpecialOperationItem>(
    SPECIAL_OPERATION_API.GET_DETAIL,
    {
      params: { id }
    }
  )
}

/**
 * 获取物品材料详情
 * @param id 物品ID
 * @returns Promise
 */
export async function getMaterialInfo(
  id: string | number
): Promise<ApiResponse<MaterialInfo>> {
  return apiClient.get<MaterialInfo>(
    SPECIAL_OPERATION_API.GET_MATERIAL_INFO,
    {
      params: { id }
    }
  )
}

/**
 * 批量获取物品材料详情
 * @param ids 物品ID数组
 * @returns Promise
 */
export async function getBulkMaterialInfo(
  ids: (string | number)[]
): Promise<ApiResponse<BulkMaterialInfoResponse>> {
  return apiClient.post<BulkMaterialInfoResponse>(
    SPECIAL_OPERATION_API.GET_BULK_MATERIAL_INFO,
    { ids }
  )
}

/**
 * 获取所有材料列表
 * @returns Promise
 */
export async function getAllMaterials(): Promise<ApiResponse<MaterialInfo[]>> {
  return apiClient.get<MaterialInfo[]>(
    SPECIAL_OPERATION_API.GET_ALL_MATERIALS,
  )
}

// 导出默认对象
export default {
  getSpecialOperationList,
  getSpecialOperationDetail,
  getMaterialInfo,
  getBulkMaterialInfo,
  getAllMaterials
}
